/*
 * @Author: your name
 * @Date: 2022-02-15 10:32:55
 * @LastEditTime: 2022-02-16 15:18:36
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \web-vue\src\store\modules\menus.js
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        menuList: [],
        permList: [],
        hasRoute: false,

        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index',
        }],
    },
    mutations: {
        setMenuList(state, menus) {
            state.menuList = menus
        },
        setPermList(state, perms) {
            state.permList = perms
        },
        changeRouteStatus(state, hasRoute) {
            state.hasRoute = hasRoute
            sessionStorage.setItem("hasRoute", hasRoute)
        },
        addTab(state, tab) {

            let index = state.editableTabs.findIndex(e => e.name === tab.name)

            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                });
            }

            state.editableTabsValue = tab.name;
        },
        resetState:(state)=>{
            //state.token = '' // token在localStorage清除的时候，就清除了
            state.menuList=[]
            state.permList=[]
            state.hasRoute=false
            state.editableTabsValue='Index'
            state.editableTabs=[{
                title: '首页',
                name: 'Index',
            }]
        }
    },
    actions: {}
}